class Solution {
public:
    string addBinary(string a, string b) {
        string ans;
        int n = a.size();
        int m = b.size();
        int f = 0;
        reverse(a.begin(), a.end());
        reverse(b.begin(), b.end());
        int x = max(n, m);
        //1 111
        for (int i = 0; i < x; i++) {
            int x1 = (a.size() >= i + 1) ? (a[i] == '1' ? 1 : 0) : 0;
            int x2 = (b.size() >= i + 1) ? (b[i] == '1' ? 1 : 0) : 0;
            cout << "x1==" << x1 << endl;
            cout << "x2==" << x2 << endl;
            int y = f + x1 + x2;
            if (y >= 2) {
                f = 1;
                if (y == 2) ans += to_string(0);
                else ans += to_string(1);
            }
            else {
                f = 0;
                ans += to_string(y);
            }
        }
        if (f)ans += to_string(1);
        cout << ans << endl;
        reverse(ans.begin(), ans.end());
        return ans;
    }
};